import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home.vue'
import Cart from '../views/cart.vue'
import Shop from '../views/shop.vue'
import User from '../views/user.vue'
import News from '../views/news.vue'
import No from '../views/no.vue'
import All from '../views/news/all.vue'
import Info from '../views/news/info.vue'
import Recommend from '../views/news/recommend.vue'
import Notice from '../views/news/notice.vue'
import Newsinfo from '../views/newsinfo.vue'
import Details from '../views/details.vue'
import Others from '../views/others.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/cart',
    name: 'Cart',
    component: Cart
  },
  {
    path: '/shop',
    name: 'Shop',
    component: Shop
  },
  {
    path: '/user',
    name: 'User',
    component: User
  },
  {
    path: '/newsinfo',
    name: 'Newsinfo',
    component: Newsinfo
  },
  {
    path: '/details',
    name: 'Details',
    component: Details
  },
  {
    path: '/news',
    name: 'News',
    component: News,
    redirect:'/news/all',
    children:[
      {
        path: 'all',
        name: 'All',
        component: All
      },
      {
        path: 'info',
        name: 'Info',
        component: Info
      },
      {
        path: 'recommend',
        name: 'Recommend',
        component: Recommend
      },
      {
        path: 'notice',
        name: 'Notice',
        component: Notice
      }
    ]
  },
  {
    path: '*',
    name: 'No',
    component: No
  },
  {
    path: '/others',
    name: 'Others',
    component: Others,
    beforeEnter(to,from,next){
      console.log(to+"......"+from)
      alert('欢迎访问others页面');
      next()
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})



export default router
